home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / c / mcomm557.zip / TXZM.C < prev    next >
C/C++ Source or Header  |  1993-09-11  |  50KB  |  1,418 lines

  1.  
  2. /*/////////////////////////////////////////////////////////////////////
  3. //                                                                   //
  4. //  TXZM.C -- zmodem protocol driver (formerly ZMP)                  //
  5. //                                                                   //
  6. //    (c) 1991,92, Mike Dumdei, 6 Holly Lane, Texarkana TX, 75503    //
  7. //                                                                   //
  8. //////////////////////////////////////////////////////////////////// */
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <stdarg.h>
  12. #include <string.h>
  13. #include <process.h>
  14. #include <ctype.h>
  15. #include <io.h>
  16. #include <dos.h>
  17. #include <bios.h>
  18. #include "comm.h"
  19. #include "ansidrv.h"
  20. #include "extra.h"
  21. #include "colors.h"
  22. #include "zmdos.h"
  23.  
  24. #if defined (__TURBOC__)
  25.   #include <dir.h>
  26.   #define ChDrive(d) setdisk((d)-1)
  27. #elif defined (__ZTC__)
  28.   #include <direct.h>
  29.   #define ChDrive(d) _chdrive(d)
  30. #elif defined (__MSC__)
  31.   int ndrives;
  32.   #define ChDrive(d) _dos_setdrive((d), &ndrives)
  33. #endif
  34.  
  35. #define ALT_C       0x2e00
  36. #define ALT_D       0x2000
  37. #define ALT_E       0x1200
  38. #define ALT_H       0x2300
  39. #define ALT_L       0x2600
  40. #define ALT_P       0x1900
  41. #define ALT_R       0x1300
  42. #define ALT_S       0x1f00
  43. #define ALT_X       0x2d00
  44. #define FK1         0x3b00
  45. #define PGUP        0x4900
  46. #define PGDN        0x5100
  47. #define ALT_EQU     0x8300
  48. #define X_ESC       0x011b
  49.  
  50. void AddToList(char *subdir);
  51. char *CaptureBaudRate(void);
  52. char *ConvertSecs(long secs);
  53. long ConvertTicks(long ticks);
  54. int Dial(void);
  55. void DrawBox(int row, int col, int nrows, int ncols, int color, int style);
  56. void DspZmodemScrn(void);
  57. char *ExpandSubDirs(char *fnames);
  58. int FileTransfer(void);
  59. void HelpFunc(void);
  60. void InitDefaults(void);
  61. void MiniTermMode(void);
  62. void ProcCmdLine(int argc, char * *argv);
  63. int prompt(char *buf, int maxlen);
  64. int RecurseSubDirs(char *sd);
  65. int RepeatDial(void);
  66. void SetFIFOLevels(int rxFIFOlevel, int txFIFOlevel);
  67. int SetParams(char *newparams);
  68. void usage(void);
  69. void vDisplay(int row, int col, char *format, ...);
  70. int waitfor(int ticks, ...);
  71. void ZMsg(int type, ...);
  72.  
  73. extern int  _C_ TestDesqView(void);
  74. extern int  _C_ DV_VideoSeg(int);
  75. extern void _C_ DV_TimeSlice(void);
  76.  
  77. /*/////////////////////////////////////////////////////////
  78. //  Configuration structure.  Structure is used to allow //
  79. //  the defaults to be changed modifying the EXE.        //
  80. //  "TXZMCFG:" is the tag to search for to find the start//
  81. //  of the structure in the EXE.                         //
  82. //////////////////////////////////////////////////////// */
  83. struct PROTCONFIG
  84. {
  85.     char    tag[8], DLPath[80], ULPath[80];
  86.     long    LocBaud, MinFifoBaud;
  87.     int     ComBase, IRQ, Vctr;
  88.     int     h_VBufSize, h_BufSize, b_VBufSize, b_BufSize;
  89.     int     TxWindow, ZExistOpts, XYExistOpts;
  90.     int     FifoTxLvl, FifoRxLvl;
  91.     char    IgnCarrier, MsrFlow, KeepTime, EscCtl, OvlyIO;
  92.     char    Color[10], Mono[10];
  93. } cfg =
  94. {
  95.     "TXZMCFG:", "", "",
  96.     0L, 1L,
  97.     0x3f8, IRQ4, VCTR4,
  98.     2048, 0, 20508, 20480,
  99.     0, 1, 2,
  100.     8, 8,
  101.     0, 0, 1, 0, 1,
  102.     {  WHT|BLU_B,  H_GRN|BLU_B,  H_RED|BLU_B,    YLW|BLU_B,
  103.        GRY|BLU_B,    YLW|BLU_B,  H_RED|BLU_B,  H_MAG|BLU_B,
  104.        CYN,              CYN_B  },
  105.     { WHT, WHT, RVRS, H_WHT, WHT, H_WHT, H_WHT, H_WHT, WHT, WHT_B }
  106. };
  107.  
  108. /*/////////////////////////////////////////////////////////
  109. //  Screen data structure                                //
  110. //////////////////////////////////////////////////////// */
  111. typedef struct
  112. {
  113.     int row, col, color, count;
  114.     char *text;
  115. } SCREENDATA;
  116.  
  117. /*/////////////////////////////////////////////////////////
  118. //  Global variables                                     //
  119. //////////////////////////////////////////////////////// */
  120. ASYNC port;                 /* ASYNC port structure */
  121. int combase, irq, vctr;     /* port address, IRQ number, & vector */
  122. int openmask = 0;           /* mask for forcing no FIFOs, no MSR intrpts */
  123. long LocBaud = 0L;          /* CPU to modem/device baud rate */
  124. char params[12] = "";       /* port parameters */
  125. char lockedbaud[12] = "";   /* locked baud parameter */
  126. char fnames[256] = "";      /* list of files to send if sending */
  127. char minsecs[10];           /* ticks to min:secs buffer */
  128. char *color;                /* pointer to list of colors */
  129. int txtcolor;               /* color of most screen message output */
  130. char buf[256];              /* general purpose buffer */
  131. int goodargs = 0;           /* got an 'r' or an 's' on command line */
  132. char *node = NULL;          /* for bbs use: LASTUSER.BBS format file name */
  133. int miniterm = 0;           /* mini-terminal mode selected */
  134. char OvlyIO;                /* overlay disk and serial I/O flag */
  135. char *flist;                /* used when expanding subdirectories */
  136. char mask[14];              /* used when expanding subdirectories */
  137. int plen;                   /* used when expanding subdirectories */
  138. int tryDV = 0;              /* cmdline switch to test for DesqView */
  139. int checkcarrier = 0;       /* check for carrier during 'waitfor' flag */
  140. int stripmask = 0xff;       /* strip high bit mask for miniterm mode */
  141. char phone[40] = "";        /* phone number to dial */
  142.  
  143. long tfBytes, tCPS;         /* total bytes transferred, average CPS */
  144. int tFiles;                 /* number of files transferred */
  145.  
  146. /*/////////////////////////////////////////////////////////
  147. //                                                       //
  148. //      Main                                             //
  149. //                                                       //
  150. //:mai////////////////////////////////////////////////// */
  151. void cdecl main(int argc, char *argv[])
  152. {
  153.     int i;
  154.  
  155.     color = ((initvid() & 0xff) == CO80) ? cfg.Color : cfg.Mono;
  156.     txtcolor = (int)color[1] & 0xff;
  157.     InitDefaults();
  158.     ProcCmdLine(argc, argv);
  159.     if (!goodargs)
  160.         usage();
  161.  
  162.     if (tryDV && TestDesqView() != 0)
  163.     {
  164.         i = DV_VideoSeg(v_seg);
  165.         if (v_seg != i)
  166.             v_seg = i, v_snow = 0;
  167.     }
  168.     if (*params)
  169.         ConnectBaud = atol(params);
  170.     if (*lockedbaud)
  171.         LocBaud = atol(lockedbaud);
  172.     if (LocBaud == 0L)
  173.         LocBaud = ConnectBaud;
  174.     if (LocBaud != 0L)
  175.     {
  176.         sprintf(params, "%ldN81", LocBaud);
  177.         if (LocBaud < cfg.MinFifoBaud)
  178.             openmask |= 0x4000;
  179.     }
  180.  
  181.     if (OvlyIO)
  182.         VBufSize = cfg.h_VBufSize, BufSize = cfg.h_BufSize;
  183.     else
  184.         VBufSize = cfg.b_VBufSize, BufSize = cfg.b_BufSize;
  185.     if (BufSize)
  186.         ZFR0 &= ~CANOVIO;
  187.  
  188.     AllocRingBuffer(&port, 2048, 4096, 0);
  189.     while (1)
  190.     {
  191.         i = async_open(&port, combase, irq, vctr|openmask, params);
  192.         if (i != 0)
  193.         {
  194.             printf("\nSerial port open error, Error code = %d\n\a", i);
  195.             exit(i - 20); /* -20 so exit code don't clash with zm result */
  196.         }
  197.         if (ConnectBaud == 0L)
  198.         {
  199.             ConnectBaud = atol(port.BPDSstr);
  200.             strcpy(params, port.BPDSstr);
  201.             if (ConnectBaud < cfg.MinFifoBaud && async_16550(&port)
  202.              && !(openmask & 0x4000))
  203.             {
  204.                 async_close(&port);
  205.                 openmask |= 0x4000;
  206.                 continue;
  207.             }
  208.         }
  209.         break;
  210.     }
  211.     async_msrflow(&port, cfg.MsrFlow);
  212.     tickhookset(1);
  213.  
  214.     if (miniterm)
  215.     {
  216.         pushscrn(0, 0, 25, 80);
  217.         SetFIFOLevels(1, 1);
  218.         MiniTermMode(), i = 0;
  219.         popscrn();
  220.     }
  221.     else
  222.     {
  223.         i = FileTransfer();
  224.         sprintf(buf, "TXZM exit code = %d", i);
  225.         v_color = WHT;
  226.         d_strat(23, 0, buf);
  227.     }
  228.     async_close(&port);
  229.     tickhookset(0);
  230.     exit(i);
  231. }
  232.  
  233. /*/////////////////////////////////////////////////////////
  234. //  AddToList                                            //
  235. //:add////////////////////////////////////////////////// */
  236. void AddToList(char *subdir)
  237. {
  238.     static char bkslsh[2] = " ";
  239.     int i, j;
  240.  
  241.     if (*(strchr(subdir, '\0') - 1) == '\\' || subdir == GetN